#include<bits/stdc++.h>
using namespace std;
const int N = 5010;
int C,t,n,k,a[N],b[N],c[N],mi,ans,mx;
signed main()
{
    freopen("festival.in","r",stdin);
    freopen("festival.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> C>>t;
	while(t--)
	{
		cin>>n>>k; mx = 0;
		for(int i = 1;i < n;i++) cin>>a[i];
		for(int i = 1;i <= k;i++) cin>>b[i];
		for(int i = 0;i <= a[1];i++)
		{
			c[1] = i; mi = i;
			for(int j = 2;j <= n;j++) c[j] = min(a[j],a[j-1]-c[j-1]),mi = min(mi,c[j]);
			if(mi < 0) continue;
			ans = 0;
			for(int j = 1;j <= n-k+1;j++) 
				for(int z = 1;z <= k;z++)
					ans += c[j+z-1]*b[z];
			mx = max(mx,ans);
		}
		cout<<mx<<'\n';
	}
    return 0;
}
